// ### 建一个用户表（有姓名,年龄,年龄,创建时间,修改时间）,使用模块加mysql模块,实现对数据的增删改查

// ###       修改时记得，把修改时间改成修改时的时间，能实现分页（选做）
let mysql=require("mysql");
let connection=mysql.createConnection({host:"127.0.0.1",user:"root",password:"root",database:"node"});
connection.connect();

// //增加数据
let newsql="insert into user(`name`,`age`,`sex`,`creatTime`,`modTime`)value('小马','20','女','2023-2-19','2023-2-23')"
connection.query(newsql,(err,data)=>{
    console.log("写入操作----------");
    console.log(err);
    console.log(data);
})

//修改数据
let updatesql="update user set age=18 where id=4";
connection.query(updatesql,(err,data)=>{
    console.log("写入操作----------");
    console.log(err);
    console.log(data);
})

//删除数据
let deletesql="delete from user where id=5";
connection.query(deletesql,(err,data)=>{
    console.log("写入操作----------");
    console.log(err);
    console.log(data);
})

//查询数据
connection.query("select * from user limit 0,5",(err,data)=>{
    console.log(err);//没错误返回null
    console.log(data);//查询时返回数组
    console.log(data[0].name);

})
let page=1;
let pagesize=2;
console.log(new Date().toLocaleString().replace("/","-").replace("/","-"));
let sql = "select * from user limit " + (page - 1) * pagesize + "," + pagesize;
connection.query(sql, (err, data) => {
    console.log(data);
});

connection.end();
